package com.yimu.lib.http.net;

import android.util.Log;

import com.yimu.lib.util.MyLogger;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 描述：TODO
 * 创建者：  Churck
 * 创建时间：2017/4/27 11:04
 * 修改者： Churck
 * 修改时间：2017/4/27 11:04
 * 版 本：v1.0
 */

public class DefaultThreadFactory implements ThreadFactory {
     int i = 0 ;
    private static final AtomicInteger poolNumber = new AtomicInteger(1);
    private final ThreadGroup group;
    private final AtomicInteger threadNumber = new AtomicInteger(1);
    private final String namePrefix;

   public DefaultThreadFactory() {
        SecurityManager s = System.getSecurityManager();
        group = (s != null) ? s.getThreadGroup() :
                Thread.currentThread().getThreadGroup();
        namePrefix = "pool-" +
                poolNumber.getAndIncrement() +
                "-thread-";
    }

    public Thread newThread(Runnable r) {
        Thread t = new Thread(group, r,
                namePrefix + threadNumber.getAndIncrement(),
                0);
        if (t.isDaemon())
            t.setDaemon(false);
        if (t.getPriority() != Thread.NORM_PRIORITY)
            t.setPriority(Thread.NORM_PRIORITY);
        MyLogger.d("创建线程了"  + ( ++i)) ;
        return t;
    }
}
